home *** CD-ROM | disk | FTP | other *** search
- /* math2.c 4.5.4 */
- void main()
- {
- float number1, number2, result;
- int operator, error;
-
- printf("Please input two numbers!\n");
- scanf("%f%f", &number1, &number2);
- printf("And now the code for the operation!\n");
- printf("1=Add, 2=Subtract, 3=Multiply, 4=Divide\n");
- scanf("%d", &operator);
- error = 1;
- if(operator == 1) /* Addition */
- {
- result = number1 + number2;
- error = 0;
- }
- if(operator == 2) /* Subtraction */
- {
- result = number1 - number2;
- error = 0;
- }
- if(operator == 3) /* Multiplication */
- {
- result = number1 * number2;
- error = 0;
- }
- if(operator == 4) /* Division */
- {
- result = number1 / number2;
- error = 0;
- }
- if(error == 1) /* None of the above conditions */
- printf("Wrong Code! Input only codes 1-4!\n");
- else
- printf("The result is %f\n", result);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-